home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / comm2.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  33KB  |  1,071 lines

  1. /***********************************************************************/
  2. /* COMM2.C - Commands E-J                                              */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1995 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Id: comm2.c 2.0 1995/01/26 16:29:54 MH Release MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /*#define DEBUG 1*/
  51.  
  52. /*man-start*********************************************************************
  53. COMMAND
  54.      edit - edit another file or switch to next file
  55.  
  56. SYNTAX
  57.      Edit [filename]
  58.  
  59. DESCRIPTION
  60.      The EDIT command allows the user to edit another file. The new file
  61.      is placed in the file ring. The previous file being edited remains
  62.      in memory and can be returned to by issuing an EDIT command without
  63.      any parameters. Several files can be edited at once, and all files
  64.      are arranged in a ring, with subsequent EDIT commands moving through
  65.      the ring, one file at a time.
  66.  
  67. COMPATIBILITY
  68.      XEDIT: Does not provide options switches.
  69.      KEDIT: Does not provide options switches.
  70.  
  71. SEE ALSO
  72.      THE, XEDIT
  73.  
  74. STATUS
  75.      Complete.
  76. **man-end**********************************************************************/
  77.  
  78. /*man-start*********************************************************************
  79. COMMAND
  80.      emsg - display message
  81.  
  82. SYNTAX
  83.      EMSG [message]
  84.  
  85. DESCRIPTION
  86.      The EMSG command displays an error message on the error line.
  87.      This command is usually issued from a macro file.
  88.  
  89. COMPATIBILITY
  90.      XEDIT: Does not support [mmmnnns text] option
  91.      KEDIT: Compatible
  92.  
  93. SEE ALSO
  94.      CMSG, MSG
  95.  
  96. STATUS
  97.      Complete.
  98. **man-end**********************************************************************/
  99. #ifdef PROTO
  100. short Emsg(CHARTYPE *params)
  101. #else
  102. short Emsg(params)
  103. CHARTYPE *params;
  104. #endif
  105. /***********************************************************************/
  106. {
  107. /*-------------------------- external data ----------------------------*/
  108. /*--------------------------- local data ------------------------------*/
  109. /*--------------------------- processing ------------------------------*/
  110. #ifdef TRACE
  111.  trace_function("comm1.c:   Emsg");
  112. #endif
  113.  display_error(0,params,FALSE);
  114. #ifdef TRACE
  115.  trace_return();
  116. #endif
  117.  return(RC_OK);
  118. }
  119. /*man-start*********************************************************************
  120. COMMAND
  121.      enter - execute a command
  122.  
  123. SYNTAX
  124.      enter
  125.  
  126. DESCRIPTION
  127.      The ENTER command executes the command currently displayed on the
  128.      command line, if the cursor is currently displayed there.
  129.      If the key associated with ENTER is pressed while in the FILEAREA,
  130.      then the cursor will move to the first column of the
  131.      next line. If the cursor is in the PREFIX area, any pending 
  132.      prefix commands will be executed. If the mode is currently in 
  133.      'insert', then a new line is added and the cursor placed on the
  134.      next line depending on the value of SET NEWLINE.
  135.  
  136.      This command can only be used by assigning it to a function key
  137.      with the DEFINE command.
  138.  
  139.      This command will be removed in a future version.
  140.  
  141. COMPATIBILITY
  142.      XEDIT: N/A
  143.      KEDIT: N/A
  144.  
  145. SEE ALSO
  146.      SOS EXECUTE
  147.  
  148. STATUS
  149.      Complete.
  150. **man-end**********************************************************************/
  151. #ifdef PROTO
  152. short Enter(CHARTYPE *params)
  153. #else
  154. short Enter(params)
  155. CHARTYPE *params;
  156. #endif
  157. /***********************************************************************/
  158. {
  159. /*------------------------- external data -----------------------------*/
  160.  extern bool INSERTMODEx;
  161.  extern bool readonly;
  162.  extern short prefix_width;
  163. /*--------------------------- local data ------------------------------*/
  164.  unsigned short x=0,y=0;
  165.  short rc=RC_OK;
  166. /*--------------------------- processing ------------------------------*/
  167. #ifdef TRACE
  168.  trace_function("comm1.c:   Enter");
  169. #endif
  170.  switch(CURRENT_VIEW->current_window)
  171.    {
  172.     case WINDOW_COMMAND:
  173.          rc = Sos_execute("");
  174.          break;
  175.     case WINDOW_PREFIX:
  176.          post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  177.          if (CURRENT_FILE->first_ppc == NULL)/* no pending prefix cmds */
  178.            {
  179.             cursor_down(TRUE);
  180.             rc = Sos_firstcol("");
  181.            }
  182.          else
  183.             Sos_doprefix("");
  184.          break;
  185.     case WINDOW_MAIN:
  186. /*---------------------------------------------------------------------*/
  187. /* If in readonly mode, scroll down 1 line...                          */
  188. /*---------------------------------------------------------------------*/
  189.          if (readonly)
  190.            {
  191.             cursor_down(TRUE);
  192.             getyx(CURRENT_WINDOW,y,x);
  193.             wmove(CURRENT_WINDOW,y,0);
  194.             break;
  195.            }
  196.          if (INSERTMODEx)
  197.            {
  198.             post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  199.             insert_new_line((CHARTYPE *)"",0,1,get_true_line(),FALSE,FALSE,CURRENT_VIEW->display_low);
  200.             break;
  201.            }
  202.          cursor_down(TRUE);
  203.          getyx(CURRENT_WINDOW,y,x);
  204.          wmove(CURRENT_WINDOW,y,0);
  205.          break;
  206.    }
  207. #ifdef TRACE
  208.  trace_return();
  209. #endif
  210.  return(rc);
  211. }
  212. /*man-start*********************************************************************
  213. COMMAND
  214.      expand - expand tab characters to spaces
  215.  
  216. SYNTAX
  217.      EXPand [target]
  218.  
  219. DESCRIPTION
  220.      The EXPAND command converts all tab characters to spaces depending
  221.      on the size of a tab determined by the SET TABS command.
  222.  
  223. COMPATIBILITY
  224.      XEDIT: Compatible.
  225.      KEDIT: Compatible.
  226.  
  227. SEE ALSO
  228.      SET TABS
  229.  
  230. STATUS
  231.      Complete.
  232. **man-end**********************************************************************/
  233. #ifdef PROTO
  234. short Expand(CHARTYPE *params)
  235. #else
  236. short Expand(params)
  237. CHARTYPE *params;
  238. #endif
  239. /***********************************************************************/
  240. {
  241. /*-------------------------- external data ----------------------------*/
  242. /*--------------------------- local data ------------------------------*/
  243.  short rc=RC_OK;
  244. /*--------------------------- processing ------------------------------*/
  245. #ifdef TRACE
  246.  trace_function("comm3.c:   Expand");
  247. #endif
  248.  rc = execute_expand(params,TRUE,TRUE,TRUE);
  249. #ifdef TRACE
  250.  trace_return();
  251. #endif
  252.  return(rc);
  253. }
  254. /*man-start*********************************************************************
  255. COMMAND
  256.      extract - obtain various internal information about THE
  257.  
  258. SYNTAX
  259.      EXTract /item/[...]
  260.  
  261. DESCRIPTION
  262.      The EXTRACT command is used to relay information about settings
  263.      within THE from within a REXX macro. EXTRACT is only valid within
  264.      a REXX macro.
  265.  
  266. COMPATIBILITY
  267.      XEDIT: Only allows '/' as delimiter.
  268.      KEDIT: Only allows '/' as delimiter.
  269.  
  270. STATUS
  271.      Complete.
  272. **man-end**********************************************************************/
  273. #ifdef PROTO
  274. short Extract(CHARTYPE *params)
  275. #else
  276. short Extract(params)
  277. CHARTYPE *params;
  278. #endif
  279. /***********************************************************************/
  280. {
  281. /*-------------------------- external data ----------------------------*/
  282.  extern bool in_macro;
  283.  extern bool rexx_support;
  284. /*--------------------------- local data ------------------------------*/
  285.  register short i=0;
  286.  short rc=RC_OK,itemno=0,num_items=0,len=0,num_values=0;
  287.  short pos=0;
  288.  CHARTYPE *args=NULL;
  289.  bool invalid_item=FALSE;
  290. /*--------------------------- processing ------------------------------*/
  291. #ifdef TRACE
  292.  trace_function("comm1.c:   Extract");
  293. #endif
  294.  if (!in_macro
  295.  ||  !rexx_support)
  296.    {
  297.     display_error(53,(CHARTYPE *)"",FALSE);
  298. #ifdef TRACE
  299.     trace_return();
  300. #endif
  301.     return(RC_INVALID_ENVIRON);
  302.    }
  303. /*---------------------------------------------------------------------*/
  304. /* Check that the first character of parameters is /.                  */
  305. /*---------------------------------------------------------------------*/
  306.  if (*(params) != '/')
  307.    {
  308.     display_error(1,params,FALSE);
  309. #ifdef TRACE
  310.     trace_return();
  311. #endif
  312.     return(RC_INVALID_OPERAND);
  313.    }
  314.  params++;                               /* throw away first delimiter */
  315.  len = strlen(params);
  316. /*---------------------------------------------------------------------*/
  317. /* Check that we have an item to extract...                            */
  318. /*---------------------------------------------------------------------*/
  319.  if (len == 0)
  320.     invalid_item = TRUE;
  321.  else
  322.     if (len == 1 && (*(params) == '/'))
  323.        invalid_item = TRUE;
  324.  if (invalid_item)
  325.    {
  326.     display_error(1,params,FALSE);
  327. #ifdef TRACE
  328.     trace_return();
  329. #endif
  330.     return(RC_INVALID_OPERAND);
  331.    }
  332. /*---------------------------------------------------------------------*/
  333. /* Allow for no trailing '/'...                                        */
  334. /*---------------------------------------------------------------------*/
  335.  if ((*(params+len-1) == '/'))
  336.     num_items = 0;
  337.  else
  338.     num_items = 1;
  339. /*---------------------------------------------------------------------*/
  340. /* Replace all / with nul character to give us seperate strings.       */
  341. /*---------------------------------------------------------------------*/
  342.  for (i=0;i<len;i++)
  343.    {
  344.     if (*(params+i) == '/')
  345.       {
  346.        *(params+i) = '\0';
  347.        num_items++;
  348.       }
  349.    }
  350. /*---------------------------------------------------------------------*/
  351. /* For each item, extract its variables...                             */
  352. /*---------------------------------------------------------------------*/
  353.  for (i=0;i<num_items;i++)
  354.    {
  355. /*---------------------------------------------------------------------*/
  356. /* First check if the item has any arguments with it.                  */
  357. /*---------------------------------------------------------------------*/
  358.     pos = strzeq(params,' ');
  359.     if (pos == (-1))
  360.        args = (CHARTYPE *)"";
  361.     else
  362.       {
  363.        *(params+pos) = '\0';
  364.        args = strtrunc(params+pos+1);
  365.       }
  366. /*---------------------------------------------------------------------*/
  367. /* Find the item in the list of valid extract options...               */
  368. /*---------------------------------------------------------------------*/
  369.     if ((itemno = find_item(params,QUERY_EXTRACT)) == (-1))
  370.        {
  371.         display_error(1,params,FALSE);
  372. #ifdef TRACE
  373.         trace_return();
  374. #endif
  375.         return(RC_INVALID_OPERAND);
  376.        }
  377. /*---------------------------------------------------------------------*/
  378. /* Get the current settings for the valid item...                      */
  379. /*---------------------------------------------------------------------*/
  380.     num_values = get_item_values(itemno,args,QUERY_EXTRACT,0L,NULL,0L);
  381. /*---------------------------------------------------------------------*/
  382. /* If the arguments to the item are invalid, return with an error.     */
  383. /*---------------------------------------------------------------------*/
  384.     if (num_values == EXTRACT_ARG_ERROR)
  385.        {
  386. #ifdef TRACE
  387.         trace_return();
  388. #endif
  389.         return(RC_INVALID_OPERAND);
  390.        }
  391. /*---------------------------------------------------------------------*/
  392. /* If the REXX variables have already been set, don't try to set them. */
  393. /*---------------------------------------------------------------------*/
  394.     if (num_values != EXTRACT_VARIABLES_SET)
  395.       {
  396.        rc = set_extract_variables(itemno);
  397.        if (rc == RC_SYSTEM_ERROR)
  398.           break;
  399.       }
  400.     params += strlen(params)+1;
  401.    }
  402.  
  403. #ifdef TRACE
  404.  trace_return();
  405. #endif
  406.  return(rc);
  407. }
  408. /*man-start*********************************************************************
  409. COMMAND
  410.      ffile - force a FILE of the current file to disk
  411.  
  412. SYNTAX
  413.      FFile  [filename]
  414.  
  415. DESCRIPTION
  416.      The FFILE command writes the current file to disk to the current
  417.      file name or to the supplied filename.
  418.      Unlike the FILE command, if the optional filename exists, this
  419.      command will overwrite the file.
  420.  
  421. COMPATIBILITY
  422.      XEDIT: N/A
  423.      KEDIT: Compatible.
  424.  
  425. DEFAULT
  426.      With no parameters, the current file is written.
  427.  
  428. SEE ALSO
  429.      FILE, SAVE, SSAVE
  430.  
  431. STATUS
  432.      Complete
  433. **man-end**********************************************************************/
  434. #ifdef PROTO
  435. short Ffile(CHARTYPE *params)
  436. #else
  437. short Ffile(params)
  438. CHARTYPE *params;
  439. #endif
  440. /***********************************************************************/
  441. {
  442. /*-------------------------- external data ----------------------------*/
  443. /*--------------------------- local data ------------------------------*/
  444.  short rc=RC_OK;
  445. /*--------------------------- processing ------------------------------*/
  446. #ifdef TRACE
  447.  trace_function("comm2.c:   Ffile");
  448. #endif
  449.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  450.  if ((rc = save_file(CURRENT_FILE,params,TRUE,CURRENT_FILE->number_lines,1L,FALSE,0,max_line_length,TRUE)) != RC_OK)
  451.    {
  452. #ifdef TRACE
  453.     trace_return();
  454. #endif
  455.     return(rc);
  456.    }
  457. /*---------------------------------------------------------------------*/
  458. /* If autosave is on at the time of FFiling, remove the .aus file...   */
  459. /*---------------------------------------------------------------------*/
  460.  if (CURRENT_FILE->autosave > 0)
  461.     rc = remove_aus_file(CURRENT_FILE);
  462.  free_view_memory();
  463. #ifdef TRACE
  464.  trace_return();
  465. #endif
  466.  return(rc);
  467. }
  468. /*man-start*********************************************************************
  469. COMMAND
  470.      file - write the current file to disk and remove from ring
  471.  
  472. SYNTAX
  473.      FILE  [filename]
  474.  
  475. DESCRIPTION
  476.      The FILE command writes the current file to disk to the current
  477.      file name or to the supplied filename.
  478.      Unlike the FFILE command, if the optional filename exists, this
  479.      command will not overwrite the file.
  480.  
  481. COMPATIBILITY
  482.      XEDIT: Compatible.
  483.      KEDIT: Compatible.
  484.  
  485. DEFAULT
  486.      With no parameters, the current file is written.
  487.  
  488. SEE ALSO
  489.      FFILE, SAVE, SSAVE
  490.  
  491. STATUS
  492.      Complete
  493. **man-end**********************************************************************/
  494. #ifdef PROTO
  495. short File(CHARTYPE *params)
  496. #else
  497. short File(params)
  498. CHARTYPE *params;
  499. #endif
  500. /***********************************************************************/
  501. {
  502. /*-------------------------- external data ----------------------------*/
  503. /*--------------------------- local data ------------------------------*/
  504.  short rc=RC_OK;
  505. /*--------------------------- processing ------------------------------*/
  506. #ifdef TRACE
  507.  trace_function("comm2.c:   File");
  508. #endif
  509.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  510. /*---------------------------------------------------------------------*/
  511. /* If we are filing the current file with the same name AND the number */
  512. /* of alterations is zero, then quit the file.                         */
  513. /* Removed to be consistant with XEDIT/KEDIT.                          */
  514. /*---------------------------------------------------------------------*/
  515. /*
  516.  if (CURRENT_FILE->save_alt == 0 && strcmp(params,"") == 0)
  517.     Quit((CHARTYPE *)"");
  518.  else
  519. */
  520.    {
  521.     if ((rc = save_file(CURRENT_FILE,params,FALSE,CURRENT_FILE->number_lines,1L,FALSE,0,max_line_length,TRUE)) != RC_OK)
  522.       {
  523. #ifdef TRACE
  524.        trace_return();
  525. #endif
  526.        return(rc);
  527.       }
  528. /*---------------------------------------------------------------------*/
  529. /* If autosave is on at the time of Filing, remove the .aus file...    */
  530. /*---------------------------------------------------------------------*/
  531.     if (CURRENT_FILE->autosave > 0)
  532.        rc = remove_aus_file(CURRENT_FILE);
  533.     free_view_memory();
  534.    }
  535. #ifdef TRACE
  536.  trace_return();
  537. #endif
  538.  return(rc);
  539. }
  540. /*man-start*********************************************************************
  541. COMMAND
  542.      fillbox - fill the marked box block with a character
  543.  
  544. SYNTAX
  545.      FILLbox [c]
  546.  
  547. DESCRIPTION
  548.      The FILLBOX command fills the marked block with the specified
  549.      character. If no parameters are supplied and the command is run
  550.      from the command line, then the box will be filled with spaces.
  551.      If the command is not run from the command line, the user is
  552.      prompted for a character to fill the box.
  553.  
  554. COMPATIBILITY
  555.      XEDIT: N/A
  556.      KEDIT: Compatible.
  557.  
  558. STATUS
  559.      Complete
  560. **man-end**********************************************************************/
  561. #ifdef PROTO
  562. short Fillbox(CHARTYPE *params)
  563. #else
  564. short Fillbox(params)
  565. CHARTYPE *params;
  566. #endif
  567. /***********************************************************************/
  568. {
  569. /*-------------------------- external data ----------------------------*/
  570.  extern VIEW_DETAILS *vd_mark;
  571. /*--------------------------- local data ------------------------------*/
  572.  CHARTYPE chr=0;
  573.  short len_params=0;
  574. /*--------------------------- processing ------------------------------*/
  575. #ifdef TRACE
  576.  trace_function("comm2.c:   Fillbox");
  577. #endif
  578.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  579. /*---------------------------------------------------------------------*/
  580. /* Validate the marked block.                                          */
  581. /*---------------------------------------------------------------------*/
  582.  if (marked_block(TRUE) != RC_OK)
  583.    {
  584. #ifdef TRACE
  585.     trace_return();
  586. #endif
  587.     return(RC_INVALID_ENVIRON);
  588.    }
  589. /*---------------------------------------------------------------------*/
  590. /* This function not valid for line blocks.                            */
  591. /*---------------------------------------------------------------------*/
  592.  if (MARK_VIEW->mark_type == M_LINE)
  593.    {
  594.     display_error(47,(CHARTYPE *)"",FALSE);
  595. #ifdef TRACE
  596.     trace_return();
  597. #endif
  598.     return(RC_INVALID_ENVIRON);
  599.    }
  600. /*---------------------------------------------------------------------*/
  601. /* Check if hex on in effect and translate hex char if required...     */
  602. /*---------------------------------------------------------------------*/
  603.  if (CURRENT_VIEW->hex)
  604.    {
  605.     if ((len_params = convert_hex_strings(params)) == (-1))
  606.       {
  607.        display_error(32,(CHARTYPE *)"",FALSE);
  608. #ifdef TRACE
  609.        trace_return();
  610. #endif
  611.        return(RC_INVALID_OPERAND);
  612.       }
  613.    }
  614.  else
  615.    len_params = strlen(params);
  616. /*---------------------------------------------------------------------*/
  617. /* Whew, now do something...                                           */
  618. /*---------------------------------------------------------------------*/
  619.  if (len_params > 1)
  620.    {
  621.     display_error(1,params,FALSE);
  622. #ifdef TRACE
  623.     trace_return();
  624. #endif
  625.     return(RC_INVALID_OPERAND);
  626.    }
  627.  if (len_params == 0)
  628.     chr = ' ';
  629.  else
  630.     chr = *(params);
  631.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND
  632.  && len_params != 1) 
  633.    {
  634.     display_prompt("Enter fill character...");
  635.     chr = (CHARTYPE)my_getch(stdscr);
  636.     clear_msgline();
  637.    }
  638.  box_operations(BOX_F,SOURCE_BLOCK,TRUE,chr);
  639. #ifdef TRACE
  640.  trace_return();
  641. #endif
  642.  return(RC_OK);
  643. }
  644. /*man-start*********************************************************************
  645. COMMAND
  646.      forward - scroll forwards [n] screens
  647.  
  648. SYNTAX
  649.      FOrward [n]
  650.  
  651. DESCRIPTION
  652.      The FORWARD command scrolls the file contents forwards the number
  653.      of screens specified.
  654.  
  655.      If 0 is specified as the number of screens to scroll, the "Top
  656.      of File" line becomes the current line. 
  657.      If the FORWARD command is issued while the current line is the 
  658.      "Bottom of File" line, the "Top of File" line becomes the 
  659.      current line.
  660.  
  661. COMPATIBILITY
  662.      XEDIT: Compatible.
  663.      KEDIT: Does not support HALF or Lines options.
  664.  
  665. DEFAULT
  666.      1
  667.  
  668. SEE ALSO
  669.      BACKWARD, TOP
  670.  
  671. STATUS
  672.      Complete
  673. **man-end**********************************************************************/
  674. #ifdef PROTO
  675. short Forward(CHARTYPE *params)
  676. #else
  677. short Forward(params)
  678. CHARTYPE *params;
  679. #endif
  680. /***********************************************************************/
  681. {
  682. /*-------------------------- external data ----------------------------*/
  683.  extern bool in_profile;
  684.  extern bool in_macro;
  685. /*--------------------------- local data ------------------------------*/
  686. #define FOR_PARAMS  1
  687.  CHARTYPE *word[FOR_PARAMS+1];
  688.  unsigned short num_params=0;
  689.  LINETYPE num_pages=0L;
  690.  unsigned short x=0,y=0;
  691.  short rc=RC_OK;
  692.  short direction=0;
  693. /*--------------------------- processing ------------------------------*/
  694. #ifdef TRACE
  695.  trace_function("comm2.c:   Forward");
  696. #endif
  697. /*---------------------------------------------------------------------*/
  698. /* Validate parameters...                                              */
  699. /*---------------------------------------------------------------------*/
  700.  num_params = param_split(params,word,FOR_PARAMS,WORD_DELIMS,TEMP_PARAM);
  701.  if (num_params == 0)
  702.     {
  703.      num_params = 1;
  704.      word[0] = (CHARTYPE *)"1";
  705.     }
  706.  if (num_params != 1)
  707.     {
  708.      display_error(1,(CHARTYPE *)word[1],FALSE);
  709. #ifdef TRACE
  710.     trace_return();
  711. #endif
  712.      return(RC_INVALID_OPERAND);
  713.     }
  714. /*---------------------------------------------------------------------*/
  715. /* If parameter is '*', set current line equal to last line in file... */
  716. /*---------------------------------------------------------------------*/
  717.  if (strcmp(word[0],"*") == 0)
  718.    {
  719.     rc = Bottom((CHARTYPE *)"");
  720. #ifdef TRACE
  721.     trace_return();
  722. #endif
  723.     return(rc);
  724.    }
  725. /*---------------------------------------------------------------------*/
  726. /* If the parameter is not a valid integer, error.                     */
  727. /*---------------------------------------------------------------------*/
  728.  if (!valid_integer(word[0]))
  729.    {
  730.     display_error(1,(CHARTYPE *)word[0],FALSE);
  731. #ifdef TRACE
  732.     trace_return();
  733. #endif
  734.     return(RC_INVALID_OPERAND);
  735.    }
  736. /*---------------------------------------------------------------------*/
  737. /* Number of screens to scroll is set here.                            */
  738. /*---------------------------------------------------------------------*/
  739.  num_pages = atol(word[0]);
  740. /*---------------------------------------------------------------------*/
  741. /* If the number specified is < 0, error...                            */
  742. /*---------------------------------------------------------------------*/
  743.  if (num_pages < 0L)
  744.    {
  745.     display_error(5,(CHARTYPE *)word[0],FALSE);
  746. #ifdef TRACE
  747.     trace_return();
  748. #endif
  749.     return(RC_INVALID_OPERAND);
  750.    }
  751. /*---------------------------------------------------------------------*/
  752. /* If the current line is already on "Bottom of File" or the parameter */
  753. /* is 0, go to the top of the file.                                    */
  754. /*---------------------------------------------------------------------*/
  755.  if (num_pages == 0
  756.  || CURRENT_BOF)
  757.    {
  758.     rc = Top((CHARTYPE *)"");
  759. #ifdef TRACE
  760.     trace_return();
  761. #endif
  762.     return(rc);
  763.    }
  764. /*---------------------------------------------------------------------*/
  765. /* Scroll the screen num_pages...                                      */
  766. /*---------------------------------------------------------------------*/
  767.  rc = scroll_page(DIRECTION_FORWARD,num_pages,FALSE);
  768. #ifdef TRACE
  769.  trace_return();
  770. #endif
  771.  return(rc);
  772. }
  773. /*man-start*********************************************************************
  774. COMMAND
  775.      get - insert into file the contents of specified file
  776.  
  777. SYNTAX
  778.      GET [fileid]
  779.  
  780. DESCRIPTION
  781.      The GET command reads a file into the current file, inserting
  782.      lines after the current line.
  783.      When no fileid is supplied the temporary file generated by the
  784.      PUT command is used.
  785.  
  786. COMPATIBILITY
  787.      XEDIT: Does not support optional firstrec - numrecs
  788.      KEDIT: Does not support optional fromlines - forlines.
  789.  
  790. SEE ALSO
  791.      PUT, PUTD
  792.  
  793. STATUS
  794.      Complete
  795. **man-end**********************************************************************/
  796. #ifdef PROTO
  797. short Get(CHARTYPE *params)
  798. #else
  799. short Get(params)
  800. CHARTYPE *params;
  801. #endif
  802. /***********************************************************************/
  803. {
  804. /*-------------------------- external data ----------------------------*/
  805.  extern CHARTYPE *tempfilename;
  806.  extern CHARTYPE *temp_cmd;
  807.  extern CHARTYPE sp_path[MAX_FILE_NAME+1] ;
  808.  extern CHARTYPE sp_fname[MAX_FILE_NAME+1] ;
  809.  extern bool in_profile;
  810. /*--------------------------- local data ------------------------------*/
  811.  CHARTYPE *filename=NULL;
  812.  FILE *fp=NULL;
  813.  LINE *curr=NULL;
  814.  LINETYPE old_number_lines=0L,true_line=0L;
  815.  short rc=RC_OK;
  816. /*--------------------------- processing ------------------------------*/
  817. #ifdef TRACE
  818.  trace_function("comm2.c:   Get");
  819. #endif
  820.  if (strcmp(params,"") == 0)   /* no fileid supplied */
  821.     filename = tempfilename;
  822.  else
  823.    {
  824.     if ((rc = splitpath(strtrans(params,OSLASH,ISLASH))) != RC_OK)
  825.       {
  826.        display_error(10,params,FALSE);
  827. #ifdef TRACE
  828.        trace_return();
  829. #endif
  830.        return(rc);
  831.       }
  832.     strcpy(temp_cmd,sp_path);
  833.     strcat(temp_cmd,sp_fname);
  834.     filename = temp_cmd;
  835.    }
  836.  
  837.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  838.  
  839.  if ((fp = fopen(filename,"r")) == NULL)
  840.    {
  841.     display_error(9,params,FALSE);
  842. #ifdef TRACE
  843.     trace_return();
  844. #endif
  845.     return(RC_ACCESS_DENIED);
  846.    }
  847.  true_line = get_true_line();
  848.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  849.  if (curr->next == NULL)   /* on bottom of file */
  850.     curr = curr->prev;
  851.  old_number_lines = CURRENT_FILE->number_lines;
  852.  if ((curr = read_file(fp,curr,filename)) == NULL)
  853.    {
  854. #ifdef TRACE
  855.     trace_return();
  856. #endif
  857.     return(RC_ACCESS_DENIED);
  858.    }
  859.  
  860.  fclose(fp);
  861.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  862. /*---------------------------------------------------------------------*/
  863. /* Fix the positioning of the marked block (if there is one and it is  */
  864. /* in the current view).                                               */
  865. /*---------------------------------------------------------------------*/
  866.  if (!in_profile)
  867.    {
  868.     adjust_marked_lines(TRUE,true_line,CURRENT_FILE->number_lines - old_number_lines);
  869.     adjust_pending_prefix(CURRENT_VIEW,TRUE,true_line,CURRENT_FILE->number_lines - old_number_lines);
  870.    }
  871. /*---------------------------------------------------------------------*/
  872. /* Increment the number of lines counter for the current file and the  */
  873. /* number of alterations.                                              */
  874. /*---------------------------------------------------------------------*/
  875.  if ((rc = increment_alt(CURRENT_FILE)) != RC_OK)
  876.    {
  877. #ifdef TRACE
  878.     trace_return();
  879. #endif
  880.     return(rc);
  881.    }
  882.  build_current_screen(); 
  883.  display_current_screen();
  884. #ifdef TRACE
  885.  trace_return();
  886. #endif
  887.  return(RC_OK);
  888. }
  889. /*man-start*********************************************************************
  890. COMMAND
  891.      help - edit help file for THE
  892.  
  893. SYNTAX
  894.      HELP
  895.  
  896. DESCRIPTION
  897.      The HELP command displays help for the editor.
  898.      Uses THE_HELP_FILE environment variable to point to the help file.
  899.  
  900. COMPATIBILITY
  901.      XEDIT: Similar in concept.
  902.      KEDIT: Similar in concept.
  903.  
  904. STATUS
  905.      Complete.
  906. **man-end**********************************************************************/
  907. #ifdef PROTO
  908. short Help(CHARTYPE *params)
  909. #else
  910. short Help(params)
  911. CHARTYPE *params;
  912. #endif
  913. /***********************************************************************/
  914. {
  915. /*------------------------- external data -----------------------------*/
  916.  extern CHARTYPE the_help_file[MAX_FILE_NAME+1];
  917. /*--------------------------- local data ------------------------------*/
  918. /*--------------------------- processing ------------------------------*/
  919. #ifdef TRACE
  920.  trace_function("comm2.c:   Help");
  921. #endif
  922. /*---------------------------------------------------------------------*/
  923. /* No arguments are allowed; error if any are present.                 */
  924. /*---------------------------------------------------------------------*/
  925.  if (strcmp(params,"") != 0)
  926.    {
  927.     display_error(1,(CHARTYPE *)params,FALSE);
  928. #ifdef TRACE
  929.     trace_return();
  930. #endif
  931.     return(RC_INVALID_OPERAND);
  932.    }
  933.  if (!file_exists(the_help_file))
  934.    {
  935.     display_error(23,(CHARTYPE *)the_help_file,FALSE);
  936. #ifdef TRACE
  937.     trace_return();
  938. #endif
  939.     return(RC_FILE_NOT_FOUND);
  940.    }
  941.  Xedit(the_help_file);
  942. #ifdef TRACE
  943.  trace_return();
  944. #endif
  945.  return(RC_OK);
  946. }
  947. /*man-start*********************************************************************
  948. COMMAND
  949.      input - insert the command line contents into the file
  950.  
  951. SYNTAX
  952.      Input [line contents]
  953.  
  954. DESCRIPTION
  955.      The INPUT command inserts the remainder of the command line into the
  956.      file after the current line.
  957.  
  958. COMPATIBILITY
  959.      XEDIT: Does not provide full input mode option.
  960.      KEDIT: Does not provide full input mode option.
  961.  
  962. STATUS
  963.      Complete.
  964. **man-end**********************************************************************/
  965. #ifdef PROTO
  966. short Input(CHARTYPE *params)
  967. #else
  968. short Input(params)
  969. CHARTYPE *params;
  970. #endif
  971. /***********************************************************************/
  972. {
  973. /*-------------------------- external data ----------------------------*/
  974. /*--------------------------- local data ------------------------------*/
  975.  short len_params=0;
  976. /*--------------------------- processing ------------------------------*/
  977. #ifdef TRACE
  978.  trace_function("comm2.c:   Input");
  979. #endif
  980.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  981.  if (CURRENT_VIEW->hex)
  982.    {
  983.     if ((len_params = convert_hex_strings(params)) == (-1))
  984.       {
  985.        display_error(32,(CHARTYPE *)"",FALSE);
  986. #ifdef TRACE
  987.        trace_return();
  988. #endif
  989.        return(RC_INVALID_OPERAND);
  990.       }
  991.    }
  992.  else
  993.    len_params = strlen(params);
  994.  insert_new_line(params,len_params,1L,get_true_line(),TRUE,TRUE,CURRENT_VIEW->display_low);
  995. #ifdef TRACE
  996.  trace_return();
  997. #endif
  998.  return(RC_OK);
  999. }
  1000. /*man-start*********************************************************************
  1001. COMMAND
  1002.      join - join a line with the line following
  1003.  
  1004. SYNTAX
  1005.      Join [ALigned]
  1006.  
  1007. DESCRIPTION
  1008.      The JOIN command makes one line out of the focus line and the
  1009.      line following.
  1010.      If ALIGNED is specified, any leading spaces in the following line
  1011.      are ignored. If ALIGNED is not specified, all characters, including
  1012.      spaces are added.
  1013.  
  1014. COMPATIBILITY
  1015.      XEDIT: Compatible.
  1016.      KEDIT: Compatible.
  1017.  
  1018. SEE ALSO
  1019.      SPLIT, SPLTJOIN
  1020.  
  1021. STATUS
  1022.      Complete.
  1023. **man-end**********************************************************************/
  1024. #ifdef PROTO
  1025. short Join(CHARTYPE *params)
  1026. #else
  1027. short Join(params)
  1028. CHARTYPE *params;
  1029. #endif
  1030. /***********************************************************************/
  1031. {
  1032. /*-------------------------- external data ----------------------------*/
  1033.  extern bool curses_started;
  1034. /*--------------------------- local data ------------------------------*/
  1035.  short rc=RC_OK;
  1036.  unsigned short x=0,y=0,col=0;
  1037.  bool aligned=FALSE;
  1038. /*--------------------------- processing ------------------------------*/
  1039. #ifdef TRACE
  1040.  trace_function("comm2.c:   Join");
  1041. #endif
  1042. /*---------------------------------------------------------------------*/
  1043. /* Check here for parameter value of 'Aligned'.                        */
  1044. /*---------------------------------------------------------------------*/
  1045.  if (equal((CHARTYPE *)"aligned",params,2))
  1046.     aligned = TRUE;
  1047.  else
  1048.     if (strcmp(params,"") == 0)
  1049.        aligned = FALSE;
  1050.     else
  1051.       {
  1052.        display_error(1,(CHARTYPE *)params,FALSE);
  1053. #ifdef TRACE
  1054.        trace_return();
  1055. #endif
  1056.        return(RC_INVALID_ENVIRON);
  1057.       }
  1058.  if (curses_started)
  1059.    {
  1060.     getyx(CURRENT_WINDOW,y,x);
  1061.     col = (x+CURRENT_VIEW->verify_col-1);
  1062.    }
  1063.  else
  1064.     col = 0;
  1065.  rc = execute_split_join(FALSE,aligned,col);
  1066. #ifdef TRACE
  1067.  trace_return();
  1068. #endif
  1069.  return(rc);
  1070. }
  1071.